package vn.aptech.scrumgroup.model;

import vn.aptech.scrumgroup.util.DrawUtil;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.Typeface;
import demo.axitdn.physic.Unit;

public class MenuItem extends AbstractBaseModel {

	public static final int ABOUT = 0;
	public static final int EXIT = 1;
	
	float x, y, radius;
	int type;
	
	public MenuItem(float x, float y, float radius, int type, int backColor, int foreColor) {
		super(backColor, foreColor);
		this.x = x;
		this.y = y;
		this.radius = radius;
		this.type = type;
	}
	
	@Override
	public boolean isPointOf(float x, float y) {
		// TODO Auto-generated method stub
		float dx = x - this.x * Unit.i;
		float dy = y - this.y * Unit.j;
		float delta = (float) Math.sqrt(dx * dx + dy * dy);
		if(delta <= (this.radius + 20)*Unit.i)
			return true;
		return false;
	}

	@Override
	public void changeColor(int color) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onDraw(Canvas c) {
		// TODO Auto-generated method stub
		Paint paint = new Paint();
		paint.setAntiAlias(true);
//		paint.setColor(Color.argb(128, 51, 112, 162));
		paint.setColor(backColor);
		paint.setAlpha(200);
		c.drawCircle(x*Unit.i, y*Unit.j, radius*Unit.i, paint);
		paint.setColor(foreColor);
		if(type == ABOUT){
			paint.setTypeface(Typeface.create("Times New Roman", Typeface.ITALIC));
			paint.setTextSize(DrawUtil.calculateTextSize("i", (radius - 6)*Unit.i, paint, 3));
			paint.setStrokeWidth(2);
			Rect rect = new Rect();
			paint.getTextBounds("i", 0, 1, rect);
			c.drawText("i", x*Unit.i - rect.width()/2 - Unit.i, y*Unit.j + rect.height()/2, paint);
		}else if(type == EXIT){
			//paint.setTypeface(Typeface.create("Times New Roman", Typeface.BOLD));
			paint.setTextSize(DrawUtil.calculateTextSize("X", (radius - 2)*Unit.i, paint, 3));
			paint.setStrokeWidth(2);
			Rect rect = new Rect();
			paint.getTextBounds("X", 0, 1, rect);
			c.drawText("X", x*Unit.i - rect.width()/2, y*Unit.j + rect.height()/2, paint);
		}
//		paint.setColor(Color.RED);
//		paint.setStyle(Style.STROKE);
//		c.drawCircle(this.x*Unit.i, this.y*Unit.j, (this.radius + 20)*Unit.i, paint);
	}

	@Override
	public void onUpdate(double t) {
		// TODO Auto-generated method stub

	}

}
